package com.example.kaogong.sys.controller;


import com.example.kaogong.common.exception.ParamsErrorException;
import com.example.kaogong.common.utils.Assert;
import com.example.kaogong.common.utils.RespBean;
import com.example.kaogong.sys.pojo.CourseVideo;
import com.example.kaogong.sys.service.ICourseVideoService;
import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  课程视频前端控制器
 * </p>
 *
 * @author  
 * @since 2022-03-29
 */
@RestController
@RequestMapping("/course-video")
@Api(tags = "课程视频接口")
@Slf4j
public class CourseVideoController {

    @Autowired
    private ICourseVideoService courseVideoService;

    @ApiOperation(value = "新增课程视频")
    @PostMapping("")
    public RespBean addCourseVideo(@Valid @RequestBody CourseVideo courseVideo) {
        log.info("request:{}", new Gson().toJson(courseVideo));
        RespBean respBean = courseVideoService.addCourseVideo(courseVideo);
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }

    @ApiOperation(value = "根据视频编号删除课程视频")
    @DeleteMapping("/{videoId}")
    public RespBean deleteCourseVideo(@PathVariable Integer videoId) {
        Assert.notNull(videoId, new ParamsErrorException("视频编号不能为空"));
        RespBean respBean = courseVideoService.deleteCourseVideo(videoId);
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }
}
